package com.demo.passenger.sys.user.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.passenger.sys.user.entity.SysUser;
import com.demo.passenger.sys.user.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weifucheng
 * @since 2019-07-13
 */
@Controller
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    ISysUserService sysUserService;

    @RequestMapping("/{type}")
    public String type(){
        return null;
    }

    @RequestMapping("/listByParams")
    @ResponseBody
    public Object listByParams(SysUser sysUser, Integer current, Integer size){
        return sysUserService.listByParams(sysUser, current, size);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public List<SysUser> listAll(){
        return sysUserService.list();
    }

    @RequestMapping("/save")
    @ResponseBody
    public Boolean save(SysUser sysUser){
        return sysUserService.saveSingle(sysUser);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Boolean update(SysUser sysUser){
        return sysUserService.saveOrUpdate(sysUser);
    }

    @RequestMapping("/read")
    @ResponseBody
    public SysUser read(SysUser sysUser){
        if(StrUtil.isNotEmpty(sysUser.getId())){
            sysUser=sysUserService.getById(sysUser);
        }
        return sysUser;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Boolean delete(SysUser sysUser){
        return sysUserService.removeById(sysUser.getId());
    }
}
